<!DOCTYPE html >
<html xmlns:th="http://www.thymeleaf.org" xmlns:tiles="http://www.thymeleaf.org">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>学生考勤管理</title>
<link type="text/css" rel="stylesheet" th:href="@{/css/page.css}"/>
<script type="text/javascript" th:src="@{/js/jquery/jquery-3.3.1.js}"></script>
<!-- mmGrid -->
<link rel="stylesheet" type="text/css" th:href="@{/plug/mmGrid/mmGrid.css}"/>
<script type="text/javascript"  th:src="@{/plug/mmGrid/mmGrid.js}" ></script>
<!-- mmGrid page -->
<link rel="stylesheet" type="text/css" th:href="@{/plug/mmGrid/mmPaginator.css}"/>
<script type="text/javascript" th:src="@{/plug/mmGrid/mmPaginator.js}" ></script>

<!-- layer -->
<link type="text/css" rel="stylesheet" th:href="@{/plug/layui/css/layui.css}"  media="all"/>
<script type="text/javascript" th:src="@{/plug/layui/layui.js}"  charset="utf-8"></script>

<link type="text/css" rel="stylesheet" th:href="@{/js/layer/skin/layer.css}"/>
<script type="text/javascript" th:src="@{/js/layer/layer.js}" ></script>
<style type="text/css">
</style>

</head>
<body>
<div  lay-allowclose="true" style="margin-left:15px; width: 98%">
<div class="first_div" style="border:none;">
	<table class="param_table" style="margin-left:10px;" >
		<tr>
			<td style="width:150px;">
				<span>开始时间：</span>
				<input type="text" id="startTime" name="startTime" class="input_0" />
			</td>
			<td style="width:150px;">
				<span>结束时间：</span>
				<input type="text" id="endTime" name="endTime" class="input_0" />
			</td>
			
		
			<td style="">
			<div class="layui-btn-group">
			  <button class="layui-btn" onclick="search()">查询</button>
			  <button class="layui-btn layui-btn-normal" onclick="sendNotify()">发送考勤通知</button>
			</div>
			</td>
		</tr>
	</table>
	
	<div style="margin:3px 10px 10px 10px;"></div>
	<div id="exampleTableUser" style="margin-top:5px;" ></div>
	<div id="paginator11-1" align="right" style="margin-right:10px;" ></div>
</div>
</div>
</body>
</html>

<script type="text/javascript" th:inline="javascript">
layui.use('laydate', function(){
	  var laydate = layui.laydate;
	  
	  //执行一个laydate实例
	  laydate.render({
	    elem: '#startTime' //指定元素
	  });
	  laydate.render({
		elem: '#endTime' //指定元素
	 });
});

$(function(){	
	//表格
	$('#exampleTableUser').mmGrid({
    	root:'rows',// 和后台数据保存列一致,对应MMGridPageVoBean rows
		url:"/ls/getAllChildSignByLimit",
    	width: 'auto',
    	height: 'auto',
    	//checkCol: true,
    	fullWidthRows: true, //表格第一次加载数据时列伸展，自动充满表格
    	showBackboard: false,
        //multiSelect: true,
        indexCol: true,  //索引列
        params:function(){
        	var param = new Object();
       	
        	param.startTime = $.trim($("#startTime").val());
        	param.id = $.trim($("#id").val());
        	param.endTime = $.trim($("#endTime").val());
        
        	return param;
        },
        cols: [{title: 'ID', name: 'id', width:60, hidden:true},
			   {title: '考勤人', name: 'name', width:50},
			   {title: '班级', name: 'className', width:50},
			   {title: '状态', name: 'state', width:50, renderer:function(val, item, rowIndex){
				   if(val == 1){
					   return "<span>正常</span>";
				   }else if(val == 2){
					   return "<span>提前</span>";
				   }else if(val == 3){
					   return "<span>迟到</span>";
				   }else if(val == 4){
					   return "<span>请假</span>";
				   }else if(val == 5){
					   return "<span>未知</span>";
				   }
			   }},
			   {title: '考勤类型', name: 'type', width:50, renderer:function(val, item, rowIndex){
				   if(val == 1){
					   return "<span>签到</span>";
				   }else if(val == 2){
					   return "<span>签退</span>";
				   }
			   }},
			   {title: '考勤人类型', name: 'kqrType', width:50, renderer:function(val, item, rowIndex){
				   if(val == 1){
					   return "<span>老师</span>";
				   }else if(val == 2){
					   return "<span>学生</span>";
				   }else if(val == 3){
					   return "<span>家长</span>";
				   }
			   }},
			   {title: '签到时间', name: 'signIn', width:50, renderer:function(val, item, rowIndex){
				   if(val){
					   return (""+val).split(" ")[0];
				   }
				   return "";
			   }}
			  
			  
           ],
        plugins : [
        	$('#paginator11-1').mmPaginator({
        		totalCountName: 'total',    //对应MMGridPageVoBean count
        		page: 1,                    //初始页
        		pageParamName: 'page',      //当前页数
        		limitParamName: 'limit', //每页数量
        		limitList: [10, 20, 30, 50]
        	})
        ]
    });
});

//查询
function search(){
	$('#exampleTableUser').mmGrid().load({"page":1});
}

// 发送当天考勤通知（所有学生，家长）
function sendNotify(){
	$.ajax({
		url: "/ls/sendChildAttendanceNotifyToday",
		type: "POST",
		success: function(res){
			if(res === 'SUCCESS' || res === 'QUEUED'){
				layer.alert('任务已提交，正在后台发送（当天仅一次）', {icon: 1});
			}else{
				layer.alert('发送失败，请稍后重试');
			}
		},
		error: function(){
			layer.alert('请求失败');
		}
	});
}

</script>